package com.elong.businesstravel.protocol.hotel;

import org.apache.http.Header;
import org.apache.http.client.HttpResponseException;
import org.json.JSONArray;
import org.json.JSONObject;

import com.elong.businesstravel.entitys.HotelImage;
import com.elong.businesstravel.entitys.HotelInfo;
import com.elong.businesstravel.protocol.baseresponse.BaseELongJsonHttpResponse;

public class GetHotelInfoResponse extends BaseELongJsonHttpResponse {

	public HotelInfo hotelInfo = new HotelInfo();
	
	@Override
	public void onSuccess(int statusCode, Header[] headers,
			JSONObject mainJsonObject) throws Throwable {
		
		JSONObject responseJsonObject = mainJsonObject.getJSONObject("response");
		JSONObject hotelinfoJsonObject = responseJsonObject.getJSONObject("hotelinfo");
		
		hotelInfo.phone = hotelinfoJsonObject.optString("phone", "");
		hotelInfo.latlng_0_coordinate = hotelinfoJsonObject.optString("latlng_0_coordinate", "");
		hotelInfo.cityId = hotelinfoJsonObject.optString("cityId", "");
		hotelInfo.roomId = hotelinfoJsonObject.optString("roomId", "");
		hotelInfo.hotelId = hotelinfoJsonObject.optString("hotelId", "");
		hotelInfo.bussName = hotelinfoJsonObject.optString("bussName", "");
		hotelInfo.id = hotelinfoJsonObject.optString("id", "");
		hotelInfo.share = hotelinfoJsonObject.optString("share", "");
		hotelInfo.chainId = hotelinfoJsonObject.optString("chainId", "");
		hotelInfo.hotelAddress = hotelinfoJsonObject.optString("hotelAddress", "");
		hotelInfo.districtId = hotelinfoJsonObject.optString("districtId", "");
		hotelInfo.pariseScore = hotelinfoJsonObject.optString("pariseScore", "");
		hotelInfo.economicChain = hotelinfoJsonObject.optString("economicChain", "");
		hotelInfo.hotelName = hotelinfoJsonObject.optString("hotelName", "");
		hotelInfo.latlng_1_coordinate = hotelinfoJsonObject.optString("latlng_1_coordinate", "");
		hotelInfo.saleCount = hotelinfoJsonObject.optString("saleCount", "");
		hotelInfo.facilities = hotelinfoJsonObject.optString("facilities", "");
		hotelInfo.product = hotelinfoJsonObject.optString("product", "");
		hotelInfo.groupId = hotelinfoJsonObject.optString("groupId", "");
		hotelInfo.districtName = hotelinfoJsonObject.optString("districtName", "");
		hotelInfo.realStar = hotelinfoJsonObject.optString("realStar", "");
		hotelInfo.canBack = hotelinfoJsonObject.optString("canBack", "");
		hotelInfo.latlng = hotelinfoJsonObject.optString("latlng", "");
		hotelInfo.manfangdays = hotelinfoJsonObject.optString("manfangdays", "");
		hotelInfo.hotelStar = hotelinfoJsonObject.optString("hotelStar", "");
		hotelInfo.saledays = hotelinfoJsonObject.optString("saledays", "");
		hotelInfo.bussId = hotelinfoJsonObject.optString("bussId", "");
		hotelInfo.mPrepay = hotelinfoJsonObject.optString("mPrepay", "");
		hotelInfo.collect = hotelinfoJsonObject.optString("collect", "");
		hotelInfo.minPrice = hotelinfoJsonObject.optString("minPrice", "");
		
		JSONObject shortshareJsonObject = hotelinfoJsonObject.getJSONObject("shortshare");
		hotelInfo.mHotelDetailShortShare.imageurl = shortshareJsonObject.optString("imageurl", "");
		hotelInfo.mHotelDetailShortShare.content = shortshareJsonObject.optString("content", "");
		hotelInfo.mHotelDetailShortShare.title = shortshareJsonObject.optString("title", "");
		hotelInfo.mHotelDetailShortShare.shareurl = shortshareJsonObject.optString("shareurl", "");
		
		JSONObject shareinfoJsonObject = hotelinfoJsonObject.getJSONObject("shareinfo");
		hotelInfo.mHotelDetailShareInfo.imageurl = shareinfoJsonObject.optString("imageurl", "");
		hotelInfo.mHotelDetailShareInfo.content = shareinfoJsonObject.optString("content", "");
		hotelInfo.mHotelDetailShareInfo.title = shareinfoJsonObject.optString("title", "");
		hotelInfo.mHotelDetailShareInfo.shareurl = shareinfoJsonObject.optString("shareurl", "");
		
		JSONObject appendInfoJsonObject = hotelinfoJsonObject.optJSONObject("appendInfo");
		if(null != appendInfoJsonObject){
			hotelInfo.descriPtion = appendInfoJsonObject.optString("descriPtion", "");
			hotelInfo.introeDitor = appendInfoJsonObject.optString("introeDitor", "");
		}
		
		JSONArray imagesJsonArray = hotelinfoJsonObject.getJSONArray("images");
		for (int i = 0; i < imagesJsonArray.length(); i++) {
			HotelImage hotelImage = new HotelImage();
			JSONObject itemImageJsonObject = imagesJsonArray.getJSONObject(i);
			hotelImage.type = itemImageJsonObject.optString("type","");
			hotelImage.location = itemImageJsonObject.optString("location","");
			hotelImage.name = itemImageJsonObject.optString("name","");
			hotelInfo.mHotelImages.add(hotelImage);
		}
		
	}

}
